package com.bestalbum.ui{
	import flash.display.MovieClip;
	import flash.events.*;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class PagerSection extends MovieClip{
		private var _sectionNumber:Number;
		private var tf:TextField;
		private var wd:Number;
		private var hg:Number;
		private var col:Number;
		private var selCol:Number = 0xFFFFFF;
		private var textAlpha:Number = 0.5;
		private var textSize:Number = 15;
		private var textFont:String = "Avanti";
		private var border:MovieClip;
		private var initFormat:TextFormat;
		private var selFormat:TextFormat;
		public static var SECTION_CLICK:String = "onSectionClick";
		
		public function PagerSection(_width:Number, _height:Number, _color:Number, _txt:String){
			wd = _width;
			hg = _height;
			col = _color;
			_sectionNumber = Number(_txt);
			
			initFormat = new TextFormat();
			initFormat.font = textFont;
			initFormat.align = "center";
			initFormat.size = textSize;
			initFormat.color = col;
			initFormat.bold = true;
			
			selFormat = new TextFormat();
			selFormat.font = textFont;
			selFormat.align = "center";
			selFormat.size = textSize;
			selFormat.color = selCol;
			selFormat.bold = true;
			
			drawBorder();
			createTextField();
			this.addEventListener(MouseEvent.CLICK, onSectionClick);
			super();
		}
		
		public function get sectionNumber():Number{
			return _sectionNumber;
		}
		
		private function onSectionClick(event:MouseEvent):void{
			var e:Event = new Event(PagerSection.SECTION_CLICK);
            dispatchEvent(e);
		}
		
		private function drawBorder(){
			
			border = new MovieClip();
			border.mouseChildren = false;
			addChild(border);
			
			border.graphics.lineStyle(1, col, 0.8);
			border.graphics.moveTo(0,0);
			border.graphics.lineTo(wd, 0);
			border.graphics.lineTo(wd, hg);
			border.graphics.lineTo(0, hg);
			border.graphics.lineTo(0, 0);
			
			//var dropShadow:DropShadowFilter = new DropShadowFilter();
			//dropShadow.color = 0xA76CAA;
			//dropShadow.blurX = 10;
			//dropShadow.blurY = 10;
			//dropShadow.angle = 0;
			//dropShadow.alpha = 0.5;
			//dropShadow.distance = 10;
			//var filtersArray:Array = new Array(dropShadow);
			//border.filters = filtersArray;
		}

		private function createTextField(){
			tf = new TextField();
			tf.x = 0;
			tf.y = 0;
			tf.alpha = textAlpha;
			tf.multiline = false;
			tf.width = wd;
			tf.height = hg; 
			tf.text = sectionNumber + "";
			tf.selectable = false;
			tf.mouseEnabled = false;
			tf.setTextFormat(initFormat);
			border.addChild(tf);
		}
		
		public function onSliderMove(){
			tf.setTextFormat(selFormat);
		}
		
		public function restore(){
			tf.setTextFormat(initFormat);
		}
	}
}